package com.seari.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Set;

public class DateUtils
{
	public static int getDaysOfMonth(String date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yy-MM");
		
		Date parse = null;
		try
		{
			parse = sdf.parse(date);
		} catch (ParseException e)
		{
			e.printStackTrace();
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(parse);
		return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
	}
	
	
	/**
	 * 获取当月所有周一
	 * @param onsetDate
	 * @param expirationDate
	 * @return
	 */
	public static List<String> getMonthMon(String onsetDate,String expirationDate) {
		SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");
		Date begin = null;
		Date end = null;
		try
		{
			begin = sdf.parse(onsetDate);
			end = sdf.parse(expirationDate);
		} catch (ParseException e)
		{
			e.printStackTrace();
		}
		Calendar c_begin = new GregorianCalendar();
		Calendar c_end = new GregorianCalendar();
		c_begin.setTime(begin);
		c_end.setTime(end);
		
		List<String> days = new ArrayList<>();
		while(c_begin.before(c_end)){
			String day = sdf.format(c_begin.getTime());
			days.add(day);
			c_begin.add(Calendar.DATE, 7);
		}
		
		return days;
		
	}
	
	public static void main(String[] args) throws ParseException  {
//		System.out.println(getDaysOfMonth("19-1"));
		getMonthMon("2019-01-28","2019-03-04");
	}

}
